//
//  HSAddOrderViewController.m
//  hsdyOrderSystem
//
//  Created by XunFengKJ on 2017/11/9.
//  Copyright © 2017年 赖国锋. All rights reserved.
//

#import "HSAddOrderViewController.h"
#import <Masonry.h>
#import <Photos/Photos.h>
#import "ZYLMultiselectView.h"
#import "HSFoodtypeModel.h"//大类模型
#import "HSTypeDetailModel.h"//类详情模型
//#define standardsSubHeight  184
#define standardsSubHeight  229
#define volumeSubHeight  92

@interface HSAddOrderViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate>
@property (strong, nonatomic)UITextField *textField;
@property (strong, nonatomic)NSMutableArray *textFieldArrM;
@property (strong, nonatomic)UIScrollView *superScrollView;
@property (strong, nonatomic) UIView *topSuperView;
//规格view
@property (strong, nonatomic) UIView *standardsView;
//规格子view
@property (strong, nonatomic) UIView *standardsSubView;
//规格子视图数量
//@property (assign, nonatomic) NSInteger standardsCount;
@property (assign, nonatomic) NSInteger standardsSubCount;
//规格子视图数组
@property (strong, nonatomic) NSMutableArray* standardsSubMArray;

//规格删除按钮
@property (strong, nonatomic) NSMutableArray* standardsDelBtnMArray;

//份量view
@property (strong, nonatomic) UIView *volumeView;
//份量子view
@property (strong, nonatomic) UIView *volumeSubView;
//份量子视图数量
@property (assign, nonatomic) NSInteger volumeSubCount;
//份量子视图数组
@property (strong, nonatomic) NSMutableArray* volumeSubMArray;
//份量删除按钮
@property (strong, nonatomic) NSMutableArray* volumeDelBtnMArray;

//图片view
@property (strong, nonatomic) UIView *photoView;
@property (strong, nonatomic) UIImageView *shopPictureImageView;//图片

@property (assign, nonatomic) BOOL isBool;//是否已弹窗
@property (strong, nonatomic) UILabel *readyChooseL;//已选分类
@property (strong, nonatomic) NSMutableArray *chooseTypeDataArr;//数据
@property (strong, nonatomic) NSMutableArray *chooseTypeResultNameArr;//已选结果
@property (strong, nonatomic) NSMutableArray *chooseTypeResultType_idArr;//已选结果
@property (strong, nonatomic) NSMutableArray *readyChooseArr;//记录上次已选
@property (strong, nonatomic)ZYLMultiselectView *zylmus;
@property (strong, nonatomic)UIView *darkView ;


@property (strong, nonatomic)NSMutableArray *namesM ;
@property (strong, nonatomic)NSMutableArray *kindsM ;
@property (strong, nonatomic)NSMutableArray *pricesM;
@property (strong, nonatomic)UIButton *sallStatusBtn;

@property (assign, nonatomic)NSInteger allID;//全部的ID
//@property (strong, nonatomic)NSMutableArray *readySelectTypeM;//已选的type
//@property (strong, nonatomic)NSMutableArray *readySelectTypeNameM;//已选的typeName
@end

@implementation HSAddOrderViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self loadTypeDataSource];//分类数据
    
    //    [self findTypeByfoodsId];//获取已选分类
}
//
//-(NSMutableArray *)readySelectTypeM{
//    if (!_readySelectTypeM) {
//        _readySelectTypeM = @[].mutableCopy;
//    }
//    return _readySelectTypeM;
//}
//
//-(NSMutableArray *)readySelectTypeNameM{
//    if (!_readySelectTypeNameM) {
//        _readySelectTypeNameM = @[].mutableCopy;
//    }
//    return _readySelectTypeNameM;
//}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.textFieldArrM = @[].mutableCopy;
    self.navigationItem.title = @"添加菜品";
    self.view.backgroundColor = LCOLOROFBACK;
    [self setUpSubView];//设置子类view
    LGFLog(@"%@ ===== %@",self.readySelectTypeNameM,self.readySelectTypeM);
}

-(void)setUpSubView{
    [self.superScrollView addSubview:self.topSuperView];
    [self.superScrollView addSubview:self.standardsView];
    self.standardsSubCount = 0;
    self.volumeSubCount = 0;
    self.isBool = YES;
    
    self.kindsM = [NSMutableArray array];
    self.pricesM = [NSMutableArray array];
    
    if (self.isFromTypeDetailVC) {//从类详情进入,赋值
        [self setValue];
        [self.superScrollView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(self.view).offset(-44);
        }];
        [self setUpBottomView];
    }else{
        [self setUpBarButtonItems];
    }
}

-(void)setUpBottomView{
    
    UIView *bottomV = [UIView new];
    [self.view addSubview:bottomV];
    WEAKSELF
    [bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(weakSelf.view);
        make.height.mas_equalTo(44);
    }];
    
    UIButton *sallStatusBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.sallStatusBtn = sallStatusBtn;
    [sallStatusBtn setTitle:@"停售" forState:UIControlStateNormal];
    [sallStatusBtn setTitle:@"可出售" forState:UIControlStateSelected];
    [sallStatusBtn setBackgroundImage:[UIColor toImage:[UIColor redColor] ] forState:UIControlStateNormal];
    [sallStatusBtn setBackgroundImage:[UIColor toImage:[UIColor blueColor] ] forState:UIControlStateSelected];
    [bottomV addSubview:sallStatusBtn];
    [sallStatusBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(bottomV);
        make.width.mas_equalTo(SCREEN_WIDTH*0.5);
    }];
    [sallStatusBtn addTarget:self touchUpInsideAction:@selector(sallStatusBtnClick)];
    
    if (self.model.available == 0) {//可用
        sallStatusBtn.selected = NO;
    }else if (self.model.available == 2){//
        sallStatusBtn.selected = YES;
    }
    
    UIButton *changeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [changeBtn setTitle:@"修改" forState:UIControlStateNormal];
    [changeBtn setBackgroundImage:[UIColor toImage:LCOLOROFNAV] forState:UIControlStateNormal];
    [bottomV addSubview:changeBtn];
    [changeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(bottomV);
        make.width.mas_equalTo(SCREEN_WIDTH*0.5);
    }];
    [changeBtn addTarget:self touchUpInsideAction:@selector(changeBtnClick)];
}

//状态点击
-(void)sallStatusBtnClick{
    WEAKSELF
    if (self.sallStatusBtn.selected) {//调可出售
        [UIAlertController alertControllerShowInController:self Title:@"提示" message:@"是否置为可出售？" cancelBlock:^{
            
        } checkBlock:^{
            [weakSelf canSallWithBtn];
        }];
        
    }else{//调停售
        [UIAlertController alertControllerShowInController:self Title:@"提示" message:@"是否置为停售？" cancelBlock:^{
            
        } checkBlock:^{
            [weakSelf sallAllWithBtn];
        }];
    }
}

#pragma mark - 可出售
-(void)canSallWithBtn{
    WEAKSELF
    [self showLoadingWithClear:YES];
    [XFPostRequest postHaveSallShopId:[BookShareUserInforDefault readUserUid] foodsId:lIntToString(self.model.typeDetail_id) success:^(id responseObject) {
        LGFLog(@"%@",responseObject);
        [weakSelf hideLoading];
        if ([[responseObject safeJsonObjectForKey:@"status"] integerValue] ==200) {
            [SOAutoHideMessageView showMessage:[responseObject safeJsonObjectForKey:@"msg"] inView:nil];
            weakSelf.sallStatusBtn.selected = NO;
//            weakSelf.model.available = NO;
            lNOTIF_POST(@"shopcanSallSuccessNoti", nil);
        }
    } failure:^(NSError *error) {
        [weakSelf hideLoading];
        [SOAutoHideMessageView showMessage:LNETWORKERROR inView:nil];
    }];
}

#pragma mark - 卖完了
-(void)sallAllWithBtn{
    WEAKSELF
    [self showLoadingWithClear:YES];
    [XFPostRequest postSallAllShopId:[BookShareUserInforDefault readUserUid] foodsId:lIntToString(self.model.typeDetail_id) success:^(id responseObject) {
        LGFLog(@"%@",responseObject);
        [weakSelf hideLoading];
        if ([[responseObject safeJsonObjectForKey:@"status"] integerValue] ==200) {
            [SOAutoHideMessageView showMessage:[responseObject safeJsonObjectForKey:@"msg"] inView:nil];
            weakSelf.sallStatusBtn.selected = YES;
//            weakSelf.model.available = YES;
             lNOTIF_POST(@"shopSallAllSuccessNoti", nil);
        }
    } failure:^(NSError *error) {
        [weakSelf hideLoading];
        [SOAutoHideMessageView showMessage:LNETWORKERROR inView:nil];
    }];
}

//修改
-(void)changeBtnClick{
    WEAKSELF
    [UIAlertController alertControllerShowInController:self Title:@"提示" message:@"是否修改？" cancelBlock:^{
        
    } checkBlock:^{
        [weakSelf rightBtnItemClick];
    }];
}

//赋值
-(void)setValue{
    for (UITextField *tx in self.textFieldArrM) {
        switch (tx.tag) {
            case 2000:
                tx.text =self.model.name;
                break;
            case 2001:
                tx.text = [NSString floatTwoPointTurnString:[self.model.price floatValue]];
                break;
            case 2002:
                tx.text =[NSString floatTwoPointTurnString:[self.model.nowPrice floatValue]];
                break;
            case 2003:
                tx.text =self.model.title;
                break;
            case 2004:
                tx.text =self.model.intro;
                break;
            default:
                break;
        }
    }
    NSDictionary *paramData = [self dictionaryWithJsonString:self.model.paramData];
    NSArray *stardDataArr = [paramData safeJsonObjectForKey:@"kinds"];//规格数据
    for (int i =0; i<stardDataArr.count; i++) {
        [self addStandardsBtnClickWithDict:stardDataArr[i]];
    }
    NSArray *pricesDataArr = [paramData safeJsonObjectForKey:@"prices"];//份量数据
    for (int i =0; i<pricesDataArr.count; i++) {
        [self addvolumeSubViewClickWithDict:pricesDataArr[i]];
    }
    
    //已选
    //    [self.chooseTypeDataArr addObject:self.typeModel];
    self.readyChooseL.text = [NSString stringWithFormat:@"已选：%@",[self.readySelectTypeNameM componentsJoinedByString:@","]];
    LGFLog(@"self.readyChooseL.text  = %@",self.readyChooseL.text);
    
    [self.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(330);
    }];
    [self.shopPictureImageView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(@240);
    }];
    [self.shopPictureImageView sd_setImageWithURL:[NSURL URLWithString:self.model.images] placeholderImage:ImageNamed(@"morentouxiang")];
}

//json格式字符串转字典：
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

#pragma mark - 获取分类数据
-(void)loadTypeDataSource{
    [self.chooseTypeDataArr removeAllObjects];
    //    [self showLoadingWithClear:YES];
    WEAKSELF
    [XFPostRequest postShopFootTypeshopId:[BookShareUserInforDefault readUserUid] success:^(id responseObject) {
        if ([responseObject[@"status"] intValue] == 200){
            LGFLog(@"responseObject = %@",responseObject);
            [weakSelf hideLoading];
            [weakSelf.chooseTypeDataArr addObjectsFromArray: [HSFoodtypeModel mj_objectArrayWithKeyValuesArray:[responseObject safeJsonObjectForKey:@"content"]]];
            HSFoodtypeModel *model = weakSelf.chooseTypeDataArr[0];//第一个，全部
            weakSelf.allID = model.type_id;
        }
        else {
            if (![[HSFoodtypeModel mj_objectArrayWithKeyValuesArray:responseObject[@"content"]] isKindOfClass:[NSArray class]]) {
                [weakSelf.chooseTypeDataArr removeAllObjects];
            }
        }
    } failure:^(NSError *error) {
        [weakSelf hideLoading];
        //        [MBProgressHUD showError:LNETWORKERROR];
        LGFLog(@"error = %@",error);
    }];
}

#pragma mark - rightButtonItems
-(void)setUpBarButtonItems{
    UIButton* rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame = CGRectMake(0, 0, 80, 40);
    [rightBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 15, 0, -15)];
    [rightBtn setTitle:@"保存" forState:UIControlStateNormal];
    rightBtn.titleLabel.font = FONT(15);
    [rightBtn addTarget:self action:@selector(rightBtnItemClick) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem =[[UIBarButtonItem alloc] initWithCustomView:rightBtn];
}

#pragma mark - 保存按钮
-(void)rightBtnItemClick{
    NSMutableDictionary *standarsDataDict = [NSMutableDictionary dictionary];
    NSMutableArray *standarsDataArr = [self getStandData].mutableCopy;//获取规格数据
    NSMutableArray *volumeDataArr = [self getvolumeData].mutableCopy;//获取份量数据
 
    [standarsDataDict setObject:standarsDataArr forKey:@"kinds"];
    [standarsDataDict setObject:volumeDataArr forKey:@"prices"];
    LGFLog(@"保存按钮 ====== %@ -- %@",standarsDataArr,volumeDataArr);
    
    if (self.chooseTypeResultType_idArr.count == 0 ) {//没选的时候，默认是传全部
        [self.chooseTypeResultType_idArr addObjectsFromArray:self.readySelectTypeM];
    }
    NSString *foodItemId = [NSArray matchingStringWithDataArr:self.chooseTypeResultType_idArr];
    NSString *name;
    NSString *price;
    NSString *nowPrice;
    NSString *title;
    NSString *intro;
    for (UITextField *tx in self.textFieldArrM) {
        switch (tx.tag) {
            case 2000:
                name = tx.text;
                break;
            case 2001:
                price = [NSString stringWithFormat:@"%zd",[tx.text integerValue]*100];
                break;
            case 2002:
                nowPrice = [NSString stringWithFormat:@"%zd",[tx.text integerValue]*100];
                break;
            case 2003:
                title = tx.text;
                break;
            case 2004:
                intro = tx.text;
                break;
            default:
                break;
        }
    }
    if (name.length == 0) {
        [SOAutoHideMessageView showMessage:@"请输入名称" inView:self.view];
    }else if (price.length == 0) {
        [SOAutoHideMessageView showMessage:@"请输入价格" inView:self.view];
    }else if (nowPrice.length == 0) {
        [SOAutoHideMessageView showMessage:@"请输入现价" inView:self.view];
    }else if (title.length == 0) {
        [SOAutoHideMessageView showMessage:@"请输入标题" inView:self.view];
    }
    //    else if (self.chooseTypeResultType_idArr.count == 0 && self.readySelectTypeM.count == 0) {
    //        [SOAutoHideMessageView showMessage:@"请选择分类" inView:self.view];
    //    }
    else if(self.shopPictureImageView.image == nil){
        [SOAutoHideMessageView showMessage:@"请选择图片" inView:self.view];
    }else{
        UIImage *pic = self.shopPictureImageView.image;
        WEAKSELF
        [self showLoadingWithClear:YES];
        if (self.isFromTypeDetailVC) {//修改
            [XFPostRequest postShopChangeByfoodItems:lIntToString(self.model.typeDetail_id) shopId:[BookShareUserInforDefault readUserUid] foodItemId:foodItemId Name:name price:price nowPrice:nowPrice images:pic intro:intro paramData:[self DataTOjsonString:standarsDataDict] title:title success:^(id responseObject) {
                [weakSelf hideLoading];
                if ([[responseObject safeJsonObjectForKey:@"status"] integerValue] == 200) {
                    [MBProgressHUD showSuccess:[responseObject safeJsonObjectForKey:@"msg"]];
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.75 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        [weakSelf.navigationController popViewControllerAnimated:YES];
                        
                    });
                    lNOTIF_POST(@"htchangeShopItemSuccessNoti", nil);
                }else{
                    [MBProgressHUD showError:[responseObject safeJsonObjectForKey:@"msg"]];
                }
                LGFLog(@"responseObject = %@",responseObject);
            } failure:^(NSError *error) {
                [weakSelf hideLoading];
                [SOAutoHideMessageView showMessage:LNETWORKERROR inView:nil];
                LGFLog(@"error = %@",error);
            }];
        }else{//保存
            [XFPostRequest postShopAddFootItemshopId:[BookShareUserInforDefault readUserUid] foodItemId:foodItemId Name:name price:price nowPrice:nowPrice images:pic intro:intro paramData:[self DataTOjsonString:standarsDataDict] title:title success:^(id responseObject) {
                [weakSelf hideLoading];
                if ([[responseObject safeJsonObjectForKey:@"status"] integerValue] == 200) {
                    [MBProgressHUD showSuccess:[responseObject safeJsonObjectForKey:@"msg"]];
                    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.75 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                        [weakSelf isContinueAdd];//是否继续添加
                    });
                    lNOTIF_POST(@"htchangeShopItemSuccessNoti", nil);
                }else{
                    [MBProgressHUD showError:[responseObject safeJsonObjectForKey:@"msg"]];
                }
                LGFLog(@"responseObject = %@",responseObject);
            } failure:^(NSError *error) {
                [weakSelf hideLoading];
                [SOAutoHideMessageView showMessage:LNETWORKERROR inView:nil];
                LGFLog(@"error = %@",error);
            }];
        }
    }
}
#pragma mark - 是否继续添加
-(void)isContinueAdd{
    WEAKSELF
    [UIAlertController alertControllerShowInController:self Title:@"提示" message:@"是否继续添加" firstTitle:@"返回列表" andHander:^{
        [weakSelf.navigationController popViewControllerAnimated:YES];
    } secondTitle:@"继续添加" andHander:^{
        //清空数据
        [self clearListData];
    }];
}

#pragma mark - 清空数据
-(void)clearListData{
    for (UITextField *tx in self.textFieldArrM) {
        tx.text = nil;
    }
    self.readyChooseL.text = @"";
    
    NSInteger conut = self.volumeSubMArray.count>0?self.volumeSubMArray.count:0;
    for (int i =0; i<conut; i++) {
        [self delBtnClick:self.volumeDelBtnMArray[i]];
    }
    
    for (int i =0; i<self.standardsSubMArray.count; i++) {
        [self standardsDelBtnClick:self.standardsDelBtnMArray[i]];
    }
    
    [self.volumeDelBtnMArray removeAllObjects];
    [self.standardsDelBtnMArray removeAllObjects];
    self.shopPictureImageView.image = nil;
}


#pragma mark - 字符串转json
-(NSString*)DataTOjsonString:(id)object{
    NSString *jsonString = nil;
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:object
                                                       options:NSJSONWritingPrettyPrinted
                                                         error:&error];
    if (!jsonData) {
        NSLog(@"Got an error: %@", error);
    } else {
        jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }
    return jsonString;
}

#pragma mark - 点击了加规格
-(void)addStandardsBtnClickWithDict:(NSDictionary *)dataDict{
    self.standardsSubCount++;
    //整个大的view
    CGFloat height = standardsSubHeight*self.standardsSubCount +10+44;
    [self.standardsView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(height);
    }];
    
    [self creatStandardsSubViewWithDict:dataDict];//添加子view
    CGFloat standardsSubViewheight = standardsSubHeight*(self.standardsSubMArray.count-1) +10+44;
    [self.standardsSubView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.standardsView).offset(standardsSubViewheight);
    }];
}

#pragma mark - 点击了加份量
-(void)addvolumeSubViewClickWithDict:(NSDictionary*)dataDict{
    self.volumeSubCount++;
    //整个大的view
    CGFloat height = 92*self.volumeSubCount +10+44;
    [self.volumeView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(height);
    }];
    
    [self creatvolumeSubViewWithDict:dataDict];//添加子view
    CGFloat volumeSubViewheight = 92*(self.volumeSubMArray.count-1) +10+45;
    [self.volumeSubView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.volumeView).offset(volumeSubViewheight);
    }];
}

#pragma mark -  获取填写的份量的数据
-(NSArray *)getvolumeData{
    LGFLog(@"份量个数 %zd",self.volumeSubMArray.count);
    NSInteger conut = self.volumeSubMArray.count>0?self.volumeSubMArray.count:0;
    [self.pricesM removeAllObjects];
    NSMutableDictionary *priceDict = [NSMutableDictionary dictionary];
    for (int i =0; i<conut;i++) {
        NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
        //        LGFLog(@"前 i = %zd self.pricesM = %@",i,self.pricesM);
        UIView* volumeSubView = self.volumeSubMArray[i];//一整个子view
        BOOL isHaveName = NO;
        for (UIView *subView in volumeSubView.subviews) {
            for (UIView *subsubView in subView.subviews) {
                if (subsubView.tag == 6000) {
                    UITextField * nameTX = (UITextField *)subsubView;
                    if ([NSString isBlankString:nameTX.text]) {
                        isHaveName = NO;
                        continue;
                    }else{
                        isHaveName = YES;
                    }
                    [dataDict setValue:nameTX.text forKey:@"name"];
                    //                    LGFLog(@"---------subsubView-%@",subsubView);
                    //                    [self.pricesM addObject:nameDict];
                    //                    LGFLog(@"nameTX = %@",nameTX.text);
                }else if (subsubView.tag == 6001){
                    UITextField * priceTX = (UITextField *)subsubView;
                    NSString *resultStr = priceTX.text;
                    //                    LGFLog(@"---------subsubView-%@",subsubView);
                    if ([priceTX.text containsString:@"."]) {
                        NSRange range;
                        range = [priceTX.text rangeOfString:@"."];
                        if (range.location != NSNotFound) {
                            NSLog(@"found at location = %zd, length = %zd",range.location,range.length);
                            NSString * tempStr = [priceTX.text substringWithRange:NSMakeRange(0, range.location+2)];
                            resultStr = [NSString stringWithFormat:@"%zd", [tempStr integerValue]*100];
                        }else{
                            NSLog(@"Not Found");
                        }
                    }else{
                         resultStr = [NSString stringWithFormat:@"%zd", [priceTX.text integerValue]*100];
                    }
                    //                    CGFloat price =[resultStr floatValue];
                    //                    [dataDict setValue:[NSString stringWithFormat:@"%f",price*100] forKey:@"price"];
                    [dataDict setValue:resultStr forKey:@"price"];
                }
            }
        }
        if (isHaveName) {
             [self.pricesM addObject:dataDict];
        }
    }
    //    [priceDict setObject:self.pricesM forKey:@"prices"];
    LGFLog(@"priceDict = %@",priceDict);
    return self.pricesM;
}
#pragma mark -  获取填写的规格的数据
-(NSArray *)getStandData{
    LGFLog(@"规格个数 %zd",self.standardsSubMArray.count);
    NSInteger conut = self.standardsSubMArray.count>0?self.standardsSubMArray.count:0;
    [self.kindsM removeAllObjects];
    NSMutableDictionary *kindDict = [NSMutableDictionary dictionary];
    for (int i =0; i<conut;i++) {
        NSMutableDictionary *dataDict = [NSMutableDictionary dictionary];
        NSMutableArray *nameArr = [NSMutableArray array];
        //        LGFLog(@"前 i = %zd self.pricesM = %@",i,self.pricesM);
        BOOL isHaveName = 0;
        UIView* standardsSubView = self.standardsSubMArray[i];//一整个子view
        for (UIView *subView in standardsSubView.subviews) {
            for (UIView *subsubView in subView.subviews) {
                
                //                 LGFLog(@"前 i = %zd nameArr = %@",i,nameArr);
                if (subsubView.tag == 7000) {
                    UITextField * kindTX = (UITextField *)subsubView;
                    if (![NSString isBlankString:kindTX.text]) {
                        [dataDict setValue:kindTX.text forKey:@"kind"];
                        isHaveName = YES;
                    }else{
                        isHaveName = NO;
                    }
                    //                     LGFLog(@"---------subsubView-%@",subsubView);
                    // [self.pricesM addObject:nameDict];
                    // LGFLog(@"nameTX = %@",nameTX.text);
                }else if (subsubView.tag == 7001 ||subsubView.tag == 7002||subsubView.tag == 7003||subsubView.tag == 7004){
                    UITextField * nameTX = (UITextField *)subsubView;
                    [nameArr addObject:nameTX.text];
                    //                     LGFLog(@"---------subsubView-%@",subsubView);
                    //                    [dataDict setValue:priceTX.text forKey:@"names"];
                }
                [dataDict setValue:nameArr forKey:@"names"];
            }
        }
        if (dataDict != nil && isHaveName) {
            [self.kindsM addObject:dataDict];
        }
        //        LGFLog(@"后 i = %zd self.pricesM = %@",i,self.pricesM);
    }
    //    [kindDict setObject:self.kindsM forKey:@"kinds"];
    return self.kindsM;
    LGFLog(@"kindDict = %@",kindDict);
}

#pragma mark - 创建规格子view
-(void)creatStandardsSubViewWithDict:(NSDictionary *)dataDict{
    self.standardsSubView = [UIView new];
    self.standardsSubView.tag = 1000 + self.standardsSubCount;
    [self.standardsSubMArray addObject:self.standardsSubView];//将view添加到数组里
    [self.standardsView addSubview:self.standardsSubView];
    CGFloat height = 45*5 + 10 + 44;
    [self.standardsSubView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.standardsView).offset(44);
        make.left.right.mas_equalTo(self.standardsView);
        make.height.mas_equalTo(height);
    }];
    
    NSArray *placeHolderData = @[@"请输入规格类型",@"输入规格名称",@"输入规格名称",@"输入规格名称",@"输入规格名称"];
    //    self.standardsSubCount = placeHolderData.count;
    for (int i =0 ;i<placeHolderData.count ;i++) {
        UIView * inputView = [[UIView alloc] initWithFrame:CGRectMake(0, i*45, SCREEN_WIDTH, 45)];
        [self.standardsSubView addSubview:inputView];
        inputView.backgroundColor = [UIColor whiteColor];
        UILabel *xingxingLabel = [[UILabel alloc] init];
        xingxingLabel.text = @"   ";
        xingxingLabel.textAlignment = NSTextAlignmentRight;
        xingxingLabel.backgroundColor = LCOLOROFBACK;
        xingxingLabel.textColor = [UIColor redColor];
        [inputView addSubview:xingxingLabel];
        [xingxingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(inputView);
            make.centerY.mas_equalTo(inputView);
            make.width.equalTo(@20);
            make.height.equalTo(@45);
        }];
        
        UITextField *textField = [[UITextField alloc] init];
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField.tag = 7000+i;
        
        textField.placeholder = placeHolderData[i];
        [inputView addSubview:textField];
        [textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(xingxingLabel.mas_right).offset(12);
            make.right.mas_equalTo(inputView).offset(-45);
            make.centerY.mas_equalTo(inputView);
        }];
        if (self.isFromTypeDetailVC) {//从详情页进来，赋值
            NSArray *dataArr = [dataDict safeJsonObjectForKey:@"names"];
            if (dataArr.count == 4) {//这个后台要确保传回来的是4
                switch (textField.tag) {
                    case 7000:
                        textField.text = [dataDict safeJsonObjectForKey:@"kind"];
                        break;
                    case 7001:
                        textField.text = dataArr[0];
                        break;
                    case 7002:
                        textField.text = dataArr[1];
                        break;
                    case 7003:
                        textField.text = dataArr[2];
                        break;
                    case 7004:
                        textField.text = dataArr[3];
                        break;
                    default:
                        break;
                }
            }
        }
        //删除按钮
        if (i == 0) {
            UIButton *delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [inputView addSubview:delBtn];
            [self.standardsDelBtnMArray addObject:delBtn];
            //            delBtn.backgroundColor = LCOLOROFNAV;
            [delBtn setImage:ImageNamed(@"delete") forState:UIControlStateNormal];
            //            [delBtn setTitle:@"-" forState:UIControlStateNormal];
            [delBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(textField.mas_right).offset(5);
                make.right.mas_equalTo(inputView);
                make.centerY.mas_equalTo(inputView);
                make.height.mas_equalTo(44);
                make.width.mas_equalTo(40);
            }];
            delBtn.tag = 1000 + self.standardsSubCount;
            [delBtn addTarget:self action:@selector(standardsDelBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        }
        
        UIView *lineView = [[UIView alloc] init];
        [inputView addSubview:lineView];
        lineView.backgroundColor = LCOLOROFBACK;
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(inputView);
            make.height.mas_equalTo(1);
        }];
    }
}

#pragma mark - 规格点击删除按钮
-(void)standardsDelBtnClick:(UIButton*)btn{
    NSLog(@"delBtnClicktag === %zd",btn.tag);
    for (int i = 0; i<self.standardsSubMArray.count; i++) {
        UIView *standardsSubView = self.standardsSubMArray[i];
        if (btn.tag == standardsSubView.tag) {
            //移除点击的view
            [standardsSubView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(@0);
            }];
            for (UIView *view in standardsSubView.subviews) {
                [view removeFromSuperview];
            }
            //从数组移除
            [self.standardsSubMArray removeObject:standardsSubView];
            self.standardsSubCount--;
            //整个大的view
            CGFloat height = standardsSubHeight*(self.standardsSubMArray.count) +10+45;
            [self.standardsView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(height);
            }];
        }
        NSLog(@"standardsView == %zd",self.standardsView.tag);
    }
    
    //其余的小view重新布局
    NSLog(@"self.volumeSubMArray.count = %zd",self.standardsSubMArray.count);
    for (int i = 0; i<self.standardsSubMArray.count; i++) {
        UIView *volumeSubView = self.standardsSubMArray[i];
        CGFloat volumeSubViewheight = standardsSubHeight*i+10+45;
        [volumeSubView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.standardsView).offset(volumeSubViewheight);
        }];
    }
}

#pragma mark - 创建份量子view
-(void)creatvolumeSubViewWithDict:(NSDictionary*)dataDict{
    self.volumeSubView = [UIView new];
    self.volumeSubView.tag = 3000 + self.volumeSubCount;
    [self.volumeSubMArray addObject:self.volumeSubView];//将view添加到数组里
    [self.volumeView addSubview:self.volumeSubView];
    [self.volumeSubView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.volumeView).offset(44);
        make.left.right.mas_equalTo(self.volumeView);
        make.height.equalTo(@90);
    }];
    
    NSArray *placeHolderData = @[@"请输入份量名称",@"输入价格"];
    for (int i =0 ;i<placeHolderData.count ;i++) {
        UIView * inputView = [[UIView alloc] initWithFrame:CGRectMake(0, i*45, SCREEN_WIDTH, 45)];
        [self.volumeSubView addSubview:inputView];
        inputView.backgroundColor = [UIColor whiteColor];
        UILabel *xingxingLabel = [[UILabel alloc] init];
        //        xingxingLabel.text = @"   ";
        xingxingLabel.textAlignment = NSTextAlignmentRight;
        xingxingLabel.backgroundColor = LCOLOROFBACK;
        xingxingLabel.textColor = [UIColor redColor];
        [inputView addSubview:xingxingLabel];
        [xingxingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(inputView);
            make.centerY.mas_equalTo(inputView);
            make.width.equalTo(@20);
            make.height.equalTo(@45);
        }];
        
        UITextField *textField = [[UITextField alloc] init];
        textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        textField.tag = 6000+i;
        textField.placeholder = placeHolderData[i];
        [inputView addSubview:textField];
        if (textField.tag == 6001) {
            textField.keyboardType = UIKeyboardTypeNumberPad;
        }else{
            textField.keyboardType = UIKeyboardTypeDefault;
        }
        [textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(xingxingLabel.mas_right).offset(12);
            make.right.mas_equalTo(inputView).offset(-45);
            make.centerY.mas_equalTo(inputView);
        }];
        if (self.isFromTypeDetailVC) {//从详情页进来，赋值
            switch (textField.tag) {
                case 6000:
                    textField.text = [dataDict safeJsonObjectForKey:@"name"];
                    break;
                case 6001:
                    if ([[dataDict safeJsonObjectForKey:@"price"] floatValue] >0) {
                        textField.text = [NSString floatTwoPointTurnString:[[dataDict safeJsonObjectForKey:@"price"] floatValue]];
                    }
                    break;
                default:
                    break;
            }
        }
        
        
        if (i == 0) {
            UIButton *delBtn = [UIButton buttonWithType:UIButtonTypeCustom];
            [inputView addSubview:delBtn];
            [self.volumeDelBtnMArray addObject:delBtn];
            //            delBtn.layer.cornerRadius = 15;
            [delBtn setImage:ImageNamed(@"delete") forState:UIControlStateNormal];
            [delBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(textField.mas_right).offset(5);
                make.right.mas_equalTo(inputView);
                make.centerY.mas_equalTo(inputView);
                make.height.mas_equalTo(30);
                make.width.mas_equalTo(30);
            }];
            delBtn.tag = 3000 + self.volumeSubCount;
            [delBtn addTarget:self action:@selector(delBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            
        }
        UIView * lineView = [[UIView alloc] init];
        [inputView addSubview:lineView];
        lineView.backgroundColor = LCOLOROFBACK;
        [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(inputView);
            make.height.mas_equalTo(1);
        }];
    }
}
#pragma mark - 份量点击删除按钮
-(void)delBtnClick:(UIButton*)btn{
    NSLog(@"delBtnClicktag === %zd",btn.tag);
    for (int i = 0; i<self.volumeSubMArray.count; i++) {
        UIView *volumeSubView = self.volumeSubMArray[i];
        if (btn.tag == volumeSubView.tag) {
            //移除点击的view
            [volumeSubView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(@0);
            }];
            for (UIView *view in volumeSubView.subviews) {
                [view removeFromSuperview];
            }
            //从数组移除
            [self.volumeSubMArray removeObject:volumeSubView];
            self.volumeSubCount--;
            
            //整个大的view
            CGFloat height = 94*(self.volumeSubMArray.count) +10+45;
            [self.volumeView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(height);
            }];
            
        }
        NSLog(@"volumeSubView.tag == %zd",volumeSubView.tag);
    }
    //    self.volumeSubView.tag
    //其余的小view重新布局
    NSLog(@"self.volumeSubMArray.count = %zd",self.volumeSubMArray.count);
    for (int i = 0; i<self.volumeSubMArray.count; i++) {
        UIView *volumeSubView = self.volumeSubMArray[i];
        CGFloat volumeSubViewheight = 92*i+10+45;
        [volumeSubView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.volumeView).offset(volumeSubViewheight);
        }];
    }
}


#pragma mark - lazy
#pragma mark - 规格view和份量view的初始化
-(UIView *)standardsView{
    if (!_standardsView) {
        _standardsView = [UIView new];
        _standardsView.backgroundColor = [UIColor clearColor];//LCOLOROFBACK;
        [self.superScrollView addSubview:_standardsView];
        WEAKSELF
        [_standardsView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(weakSelf.superScrollView);
            make.top.mas_equalTo(weakSelf.superScrollView.mas_top).offset(6*45 +30);
            make.height.mas_equalTo(44);
            make.width.mas_equalTo(SCREEN_WIDTH);
        }];
        
        UIButton *addStandardsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_standardsView addSubview:addStandardsBtn];
        addStandardsBtn.backgroundColor = LCOLOROFNAV;
        addStandardsBtn.titleLabel.font = FONT(15);
        addStandardsBtn.layer.cornerRadius = 17;
        addStandardsBtn.layer.masksToBounds = YES;
        [addStandardsBtn setTitle:@"+规格" forState:UIControlStateNormal];
        [addStandardsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(_standardsView).offset(16);
            make.top.mas_equalTo(_standardsView).offset(8);
            make.height.mas_equalTo(34);
            make.width.mas_equalTo(80);
        }];
        [addStandardsBtn  addTarget:self action:@selector(addStandardsBtnClick) forControlEvents:UIControlEventTouchUpInside];
        //份量
        self.volumeView = [UIView new];
        self.volumeView.backgroundColor = LCOLOROFBACK;
        [self.superScrollView addSubview:self.volumeView];
        [self.volumeView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(weakSelf.superScrollView);
            make.top.mas_equalTo(_standardsView.mas_bottom).offset(5);
            make.height.mas_equalTo(44);
            make.width.mas_equalTo(SCREEN_WIDTH);
        }];
        
        UIButton *addvolumeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.volumeView addSubview:addvolumeBtn];
        addvolumeBtn.backgroundColor = LCOLOROFNAV;
        addvolumeBtn.titleLabel.font = FONT(15);
        addvolumeBtn.layer.cornerRadius = 17;
        addvolumeBtn.layer.masksToBounds = YES;
        [addvolumeBtn setTitle:@"+份量" forState:UIControlStateNormal];
        [addvolumeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.volumeView).offset(16);
            make.top.mas_equalTo(self.volumeView).offset(8);
            make.height.mas_equalTo(34);
            make.width.mas_equalTo(80);
        }];
        [addvolumeBtn  addTarget:self action:@selector(addvolumeSubViewClick) forControlEvents:UIControlEventTouchUpInside];
        
        //添加图片
        self.photoView =[UIView new];
        self.photoView.backgroundColor = [UIColor clearColor];
        [self.superScrollView addSubview:self.photoView];
        [self.photoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(weakSelf.superScrollView);
            make.top.mas_equalTo(self.volumeView.mas_bottom).offset(5);
            make.height.mas_equalTo(44);
            make.width.mas_equalTo(SCREEN_WIDTH);
            make.bottom.mas_equalTo(self.superScrollView).offset(-20);
        }];
        
        UIButton *addphotoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self.photoView addSubview:addphotoBtn];
        addphotoBtn.backgroundColor = LCOLOROFNAV;
        addphotoBtn.titleLabel.font = FONT(15);
        addphotoBtn.layer.cornerRadius = 17;
        addphotoBtn.layer.masksToBounds = YES;
        [addphotoBtn setTitle:@"+照片（必选项）" forState:UIControlStateNormal];
        [addphotoBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.photoView).offset(16);
            make.top.mas_equalTo(self.photoView).offset(8);
            make.height.mas_equalTo(34);
            make.width.mas_equalTo(120);
        }];
        [addphotoBtn  addTarget:self action:@selector(addphotoBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        
        UIImageView *shopPictureImageView = [[UIImageView alloc] init];
        self.shopPictureImageView = shopPictureImageView;
        [self.photoView addSubview:shopPictureImageView];
        [shopPictureImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf.photoView);
            make.top.mas_equalTo(addphotoBtn.mas_bottom).offset(12);
            make.height.mas_equalTo(0);
            make.width.mas_equalTo(240);
        }];
    }
    return _standardsView;
}
-(void)addStandardsBtnClick{
    [self addStandardsBtnClickWithDict:nil];
}
-(void)addvolumeSubViewClick{
    [self addvolumeSubViewClickWithDict:nil];
}

#pragma mark - 最底部view
-(UIView *)superScrollView{
    if (!_superScrollView) {
        _superScrollView = [[UIScrollView alloc]init];
        [self.view addSubview:_superScrollView];
        [_superScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.top.bottom.mas_equalTo(self.view);
            make.width.mas_equalTo(SCREEN_WIDTH);
        }];
    }
    return _superScrollView;
}

#pragma mark - 顶部的6个输入
-(UIView *)topSuperView{
    if (!_topSuperView) {
        NSArray *preData = @[@"名称",@"价格",@"现价",@"标题",@"描述"];
        NSArray *placeHolderData = @[@"请输入菜品名称",@"输入价格",@"输入现价",@"输入标题",@"输入描述"];
        _topSuperView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, SCREEN_WIDTH, (preData.count+1)*45)];
        for (int i =0; i<placeHolderData.count; i++) {
            UIView * inputView = [[UIView alloc] initWithFrame:CGRectMake(0, i*45, SCREEN_WIDTH, 45)];
            [_topSuperView addSubview:inputView];
            inputView.backgroundColor = [UIColor whiteColor];
            //左侧星星
            UILabel *xingxingLabel = [[UILabel alloc] init];
            xingxingLabel.text = [NSString stringWithFormat:@"* %@",preData[i]];
            //需要设置的位置
            NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:xingxingLabel.text];
            NSRange redRange = NSMakeRange(0, 2);
            [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
            //设置颜色
            [xingxingLabel setAttributedText:noteStr];
            
            [inputView addSubview:xingxingLabel];
            [xingxingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(inputView).offset(12);
                make.centerY.mas_equalTo(inputView);
                make.width.equalTo(@50);
            }];
            xingxingLabel.hidden = i== 4;//第四个非必须
            //输入框
            UITextField *textField = [[UITextField alloc] init];
            if (i == 1 || i == 2) {
                textField.keyboardType = UIKeyboardTypeNumberPad;
            }else{
                textField.keyboardType = UIKeyboardTypeDefault;
            }
            self.textField = textField;
            [self.textFieldArrM addObject:textField];
            textField.clearButtonMode = UITextFieldViewModeWhileEditing;
            textField.tag = 2000+i;
            textField.placeholder = placeHolderData[i];
            [inputView addSubview:textField];
            [textField mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(xingxingLabel.mas_right).offset(12);
                make.right.mas_equalTo(inputView);
                make.height.mas_equalTo(inputView);
                make.centerY.mas_equalTo(inputView);
            }];
            
            //下划线
            UIView * lineView = [[UIView alloc] init];
            [inputView addSubview:lineView];
            lineView.backgroundColor = LCOLOROFBACK;
            [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.bottom.mas_equalTo(inputView);
                make.height.mas_equalTo(1);
            }];
        }
        
        ///选择分类
        UIView * inputView = [[UIView alloc] initWithFrame:CGRectMake(0, 5*45, SCREEN_WIDTH, 45)];
        inputView.backgroundColor = [UIColor whiteColor];
        [_topSuperView addSubview:inputView];
        //左侧星星
        UILabel *xingxingLabel = [[UILabel alloc] init];
        xingxingLabel.text = @"*";
        xingxingLabel.textColor = [UIColor redColor];
        [inputView addSubview:xingxingLabel];
        [xingxingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(inputView).offset(12);
            make.bottom.mas_equalTo(inputView);
            make.width.equalTo(@10);
            make.height.equalTo(@45);
        }];
        
        UIButton *chooseTypeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        chooseTypeBtn.layer.cornerRadius = 4;
        [inputView addSubview:chooseTypeBtn];
        [chooseTypeBtn setTitle:@"选择分类" forState:0];
        chooseTypeBtn.titleLabel.font = FONT(15);
        chooseTypeBtn.backgroundColor = LCOLOROFNAV;
        [chooseTypeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(xingxingLabel.mas_right).offset(5);
            make.centerY.mas_equalTo(xingxingLabel);
            make.height.mas_equalTo(34);
            make.width.mas_equalTo(80);
        }];
        [chooseTypeBtn addTarget:self touchUpInsideAction:@selector(chooseTypeBtnClick)];
        
        //右侧显示已选分类
        UILabel *readyChooseL = [[UILabel alloc] init];
        self.readyChooseL = readyChooseL;
        [readyChooseL sizeToFit];
        readyChooseL.font = FONT(13);
        readyChooseL.textColor = LCOLOROFNAV;
        [inputView addSubview:readyChooseL];
        [readyChooseL mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(chooseTypeBtn.mas_right).offset(5);
            make.right.mas_equalTo(inputView).offset(-8);
            make.centerY.mas_equalTo(xingxingLabel);
        }];
    }
    return _topSuperView;
}

-(void)resightKeyBoard{
    for (UITextField *tx in self.textFieldArrM) {
        [tx resignFirstResponder];
    }
}

#pragma mark - 选择分类
-(void)chooseTypeBtnClick{
    [self resightKeyBoard];
    if (self.isBool) {
        self.isBool = NO;
        // 暗黑色的view
        UIView *darkView = [[UIView alloc] init];
        self.darkView = darkView;
        [darkView setAlpha:0.6];
        [darkView setUserInteractionEnabled:YES];
        [darkView setFrame:(CGRect){0, 0, SCREEN_WIDTH,SCREEN_HEIGHT}];
        [darkView setBackgroundColor:[UIColor blackColor]];
        [kAppWindow addSubview:darkView];
        WEAKSELF
        [darkView addTouches:^{
            [weakSelf dismiss];
        }];
        ZYLMultiselectView *zylmus = [[ZYLMultiselectView alloc] initWithFrame:CGRectMake(20,SCREEN_HEIGHT*0.5-(self.chooseTypeDataArr.count>8?8:self.chooseTypeDataArr.count+2)*50*0.5, SCREEN_WIDTH - 40, (self.chooseTypeDataArr.count>8?8:self.chooseTypeDataArr.count+2)*50)];
        self.zylmus = zylmus;
        zylmus.dataArr = self.chooseTypeDataArr;//全部的数据模型
        zylmus.heraderStr = @"选择分类";
        zylmus.diyBackgroundColor = XFUIColorFromRGB(0x06C2AD);
        
        if (self.readyChooseArr.count != 0) {
            [zylmus.resultArr addObjectsFromArray:self.readyChooseArr];
        }else{
            [zylmus.resultArr addObjectsFromArray:self.readySelectTypeM];
            if (self.readySelectTypeM.count == 0) {//新增的时候
                [zylmus.resultArr addObject:lIntToString(self.allID)];//全部
            }
            LGFLog(@"需要选好的下标是：self.readySelectTypeM = %@",self.readySelectTypeM);
            //            [zylmus];
        }
        [kAppWindow addSubview:zylmus];
        
        __weak __typeof(self) weakself = self;
        zylmus.SelectBlock = ^(NSMutableArray *selectArr,BOOL isSureBtn){//isSureBtn是否点击确定按钮
            if (isSureBtn) {
                if (selectArr.count>0) {
                    [self.readyChooseArr removeAllObjects]; //已选
                    [self.chooseTypeResultNameArr removeAllObjects];
                    [self.chooseTypeResultType_idArr removeAllObjects];
                    [self.readyChooseArr addObjectsFromArray:selectArr];
                    for (int i = 0; i < selectArr.count; i ++) {
                        int type_id = [selectArr[i] intValue];
                        
                        for (int j=0; j<weakself.chooseTypeDataArr.count; j++) {
                            HSFoodtypeModel *model = weakself.chooseTypeDataArr[j];
                            if (type_id == model.type_id) {
                                [self.chooseTypeResultNameArr addObject:model.name];
                                [self.chooseTypeResultType_idArr addObject:[NSString stringWithFormat:@"%zd",model.type_id]];
                            }
                        }
                        //                        HSFoodtypeModel *model = weakself.chooseTypeDataArr[i];
                        //                        [self.chooseTypeResultNameArr addObject:model.name];
                        //                        [self.chooseTypeResultType_idArr addObject:[NSString stringWithFormat:@"%zd",model.type_id]];
                    }
                    LGFLog(@"chooseTypeResultNameArr = %@",self.chooseTypeResultNameArr);
                    //                    [self.zylmus.resultArr removeAllObjects];
                    self.readyChooseL.text = [NSString stringWithFormat:@"已选：%@",[self.chooseTypeResultNameArr componentsJoinedByString:@","]];
                }else{
                    [self.readyChooseArr removeAllObjects];
                    [self.chooseTypeResultNameArr removeAllObjects];
                    [self.chooseTypeResultType_idArr removeAllObjects];
                    self.readyChooseL.text = @"";
                    [SOAutoHideMessageView showMessage:@"您未选择任何分类" inView:self.view];
                }
                [self.zylmus.resultArr removeAllObjects];
            }
            [darkView removeFromSuperview];
            weakself.isBool = YES;
        };
    }
}

//弹框消失
-(void)dismiss{
    [self.zylmus disMiss];
    [self.darkView removeFromSuperview];
    self.isBool = YES;
}
#pragma mark - lazy
-(NSMutableArray *)volumeSubMArray{
    if (!_volumeSubMArray) {
        _volumeSubMArray = @[].mutableCopy;
    }
    return _volumeSubMArray;
}

-(NSMutableArray *)standardsSubMArray{
    if (!_standardsSubMArray) {
        _standardsSubMArray = @[].mutableCopy;
    }
    return _standardsSubMArray;
}

-(NSMutableArray *)standardsDelBtnMArray{
    if (!_standardsDelBtnMArray) {
        _standardsDelBtnMArray = @[].mutableCopy;
    }
    return _standardsDelBtnMArray;
}

-(NSMutableArray *)volumeDelBtnMArray{
    if (!_volumeDelBtnMArray) {
        _volumeDelBtnMArray = @[].mutableCopy;
    }
    return _volumeDelBtnMArray;
}

-(NSMutableArray *)chooseTypeDataArr{
    if (!_chooseTypeDataArr) {
        _chooseTypeDataArr = @[].mutableCopy;
    }
    return _chooseTypeDataArr;
}

-(NSMutableArray *)chooseTypeResultNameArr{
    if (!_chooseTypeResultNameArr) {
        _chooseTypeResultNameArr = @[].mutableCopy;
    }
    return _chooseTypeResultNameArr;
}
-(NSMutableArray *)chooseTypeResultType_idArr{
    if (!_chooseTypeResultType_idArr) {
        _chooseTypeResultType_idArr = @[].mutableCopy;
    }
    return _chooseTypeResultType_idArr;
}

-(NSMutableArray *)readyChooseArr{
    if (!_readyChooseArr) {
        _readyChooseArr = @[].mutableCopy;
    }
    return _readyChooseArr;
}


#pragma mark - 添加照片
-(void)addphotoBtnClick{
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusRestricted ||
        status == PHAuthorizationStatusDenied) {// 没有权限
    }else{
        [self callActionSheetFunc];
    }
}

#pragma mark - 调用相册方法
/**
 *  调用ActionSheet
 */
- (void)callActionSheetFunc{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"选择图片"
                                                       delegate:self
                                              cancelButtonTitle:@"取消"
                                         destructiveButtonTitle:nil
                                              otherButtonTitles:@"摄像头获取", @"从相册选择", nil];
    sheet.tag = 1000;
    [sheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];
    [sheet showInView:[UIApplication sharedApplication].keyWindow];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (actionSheet.tag == 1000) {
        UIImagePickerController *controller = [[UIImagePickerController alloc] init];
        controller.allowsEditing = YES;
        controller.delegate = self;
        if (buttonIndex == 1){
            controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        }
        else if (buttonIndex == 0){
            controller.sourceType = UIImagePickerControllerSourceTypeCamera;
        }
        else{
            return;
        }
        [self presentViewController:controller animated:YES completion:NULL];
    }
}

/**
 *  选择图片后调用
 */
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
    WEAKSELF
    [picker dismissViewControllerAnimated:YES completion:^{
        weakSelf.shopPictureImageView.image = image;
        [weakSelf.photoView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.mas_equalTo(330);
        }];
        [weakSelf.shopPictureImageView mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.equalTo(@240);
        }];
    }];
}
@end

